//
//  BaseViewModel.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/4/6.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "BaseViewModel.h"
#import "UIAlertControllerUtil.h"
#import "RefreshUtil.h"

@implementation BaseViewModel

#pragma mark - Initialize
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUpMJModel];
    }
    return self;
}

#pragma mark - Delegate NetworkingBaseManagerAPISuccessCallbackDelegate
- (void)manager:(NetworkingBaseManager *)manager callAPIDidSuccessWithParams:(NSDictionary *)responseParams{
    NSAssert(NO, @"未重写网络加载成功返回代理事件(BaseViewModel)");
    
}
#pragma mark - Delegate NetworkingBaseManagerValidator
- (BOOL)isCorrectWithCallbackData:(NSDictionary *)data{
//    NSAssert(NO, @"未重写判断网络返回数据正确性代理事件(BaseViewModel)");
    NSInteger stateCode = [[data objectForKey:@"stateCode"] integerValue];
    if (stateCode == 100||stateCode == 101|| stateCode == 102|| stateCode == 103) {
        return YES;
    }else{
        [UIAlertControllerUtil generateInfoControllerWithTitle:[NSString stringWithFormat:@"%ld",stateCode] message:[data objectForKey:@"stateMessage"]];
        if (self.failViewObject != nil) {
            if ([self.failViewObject isKindOfClass:[UITableView class]]) {
                UITableView *tableView = self.failViewObject;
                [tableView.mj_footer endRefreshing];
            }else if ([self.failViewObject isKindOfClass:[UICollectionView class]]){
                UICollectionView *collection = self.failViewObject;
                [collection.mj_footer endRefreshing];
            }
        }
        return NO;
    }
}

#pragma mark - Public
-(void)loadRequest{
    NSAssert(NO, @"未重写加载网络请求方法(BaseViewModel)");
}

#pragma mark - Private
- (void)setUpMJModel{
//    DDLogVerbose(@"未重写MJModel设置方法(BaseViewModel)（可选）");
}

#pragma mark - Getter
-(id)modelObject{
//    DDLogVerbose(@"未重写需要暴露出来的网络数据model");
   return _modelObject;
}

@end
